// Author: wsfuyibing <682805@qq.com>
// Date: 2025-06-20

package config

import (
	"gitee.com/go-libs/config"
)

// Runtime
// 地图配置.
var Runtime RuntimeConfig

const (
	DefaultLoginLogRetainDays = 30
	DefaultMoneyUnit          = "豆"
	DefaultOrderLifetime      = 600
)

type (
	// RuntimeConfig
	// 地图配置接口.
	RuntimeConfig interface {
		GetLoginLogRetainDays() int
		GetMoneyUnit() string
		GetOrderLifetime() int64
	}

	runtimeConfig struct {
		LoginLogRetainDays int    `yaml:"login-log-retain-days"`
		MoneyUnit          string `yaml:"money-unit"`
		OrderLifetime      int64  `yaml:"order-lifetime"`
	}
)

// +---------------------------------------------------------------------------+
// | Interface methods                                                         |
// +---------------------------------------------------------------------------+

func (o *runtimeConfig) GetLoginLogRetainDays() int { return o.LoginLogRetainDays }
func (o *runtimeConfig) GetMoneyUnit() string       { return o.MoneyUnit }
func (o *runtimeConfig) GetOrderLifetime() int64    { return o.OrderLifetime }

// +---------------------------------------------------------------------------+
// | Hook methods                                                              |
// +---------------------------------------------------------------------------+

func (o *runtimeConfig) After() {
	if o.LoginLogRetainDays == 0 {
		o.LoginLogRetainDays = DefaultLoginLogRetainDays
	}
	if o.MoneyUnit == "" {
		o.MoneyUnit = DefaultMoneyUnit
	}
	if o.OrderLifetime == 0 {
		o.OrderLifetime = DefaultOrderLifetime
	}
}

// +---------------------------------------------------------------------------+
// | Access methods                                                            |
// +---------------------------------------------------------------------------+

func (o *runtimeConfig) init() *runtimeConfig {
	_ = config.Seek("runtime.yaml", "runtime.yml").ScanYaml(o)
	return o
}
